<?php
error_reporting(E_ALL);

include_once 'common_classes.php';
include_once 'results_grid.php';

$hasStarted = false;
$grid;

class Question {
	private $question = "";
	private $scores;
	private $i = 0;

	public function addScore($score) {
		$this->scores[$this->i] = $score;
		$this->i++;
	}

	public function setQuestion($input) {
		$this->question = $input;
	}
	
	public function getQuestion() {
		return $this->question;
	}

	public function getScores() {
		return $this->scores;
	}
}

function getQuestions() {
	$grid = getGrid();
	
	return $grid->getQuestions();
}

function getRankings() {
	$grid = getGrid();
	$result;

	$rankings = $grid->getRankings();
	$count = count($rankings);
	$topscore = $rankings[0][1];
	
	for($i = 0; $i < $count; $i++) {
		$name = $rankings[$i][0];
		$total = $rankings[$i][1];
		$result[$i][0] = $name;
		$result[$i][1] = $total;	
	}
	
	return $result;
}

function getGrid() {
	global $hasStarted;
	
	if(!$hasStarted)
		session_start();
	
	$hasStarted = true;
	
	$grid = unserialize($_SESSION['grid']);
	return $grid;
}

?>